interface BaseObject {
    [key: string]: any
}

type SearchParamsGetter<T> = (defaultValue?: Partial<T>) => T;

interface QueryInventoryRequest {
    poiIds?: string[];
    skuName?: string;
    category?: string;
    mis?: string;
}

const searchParams = {
    poiIds: [],
    skuName: '',
    category: '',
};



// const getSearchParamsWithDefaultValue = function(searchParams: any, defaultValue?: Partial<BaseObject>) {
//     return Object.assign({}, searchParams, defaultValue);
// }

// const searchParamsGetterGenerator = function <T>(defaultSearchParams?: Partial<QueryInventoryRequest>) {
//     return function (defalutVal?: Partial<T>): T {
//         return getSearchParamsWithDefaultValue(defaultSearchParams, defalutVal);
//     }
// }

// const getSearchParams = function <T>(defalutVal?: Partial<T>): T {
//     const getter: SearchParamsGetter<T> = searchParamsGetterGenerator<T>(searchParams);
//     return getter(defalutVal)
// }

// console.log(getSearchParams<QueryInventoryRequest>({ skuName: 'zs' }));


interface ResponseForTablePro {
    data: BaseObject | any[];
    total: number;
}

interface ResponseProcessor {
    (res: BaseObject): ResponseForTablePro;
} 

const responseProcessorGenerator = () => (res: BaseObject) => ({
    data: (res && res.data) || [],
    total: (res && res.total) || 0,
});

const responseProcessor: ResponseProcessor = responseProcessorGenerator();




type BuildParamsGenerator<T> = (parmas: Partial<T>, tableParams: BaseObject) => Partial<T>

const buildParamsGenerator = function <T>() {
    return function (params: Partial<T>, tableParams: BaseObject): Partial<T> {
        const result = {
            ...params,
            paging: {
                offset: tableParams.paging.offset,
                limit: tableParams.paging.limit,
            },
        };
        return result;
    };
};

const buildParams: BuildParamsGenerator<QueryInventoryRequest> = buildParamsGenerator();
console.log(buildParams({ skuName: 'zs' }, { paging: { offset: 0, limit: 20 } }));

